package com.guigu.guliorder.controller;


import com.guigu.gulicommon.entity.pojo.res.Res;
import com.guigu.gulicommon.entity.vo.OmsOrderVo;
import com.guigu.guliorder.entity.dto.SubmitOrderDto;
import com.guigu.guliorder.entity.pojo.CreatOrderPoJo;
import com.guigu.guliorder.entity.vo.OrderConfirmsVo;
import com.guigu.guliorder.service.IOmsOrderService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import static com.guigu.gulicommon.constant.CheckParametersConstant.ORDER_SN_CANNOT_BE_NULL;

/**
 * 订单 前端控制器
 * </p>
 *
 * @author 陈俊杰
 * @since 2024-08-15
 */
@Log4j2
@RestController
@RequestMapping("/oms-order")
@Valid
public class OmsOrderController {
    @Autowired
    private IOmsOrderService orderService;

    /**
     * 获取订单防冲令牌
     *
     * @return 订单防冲令牌
     */
    @GetMapping("/getOrderToken")
    public Res<String> getOrderToken() {
        return orderService.getOrderToken();
    }

    /**
     * 提交订单
     *
     * @param dto 提交订单数据
     * @return 提交订单结果
     */
    @PostMapping("/submitOrder")
    public Res<CreatOrderPoJo> submitOrder(@Valid @RequestBody SubmitOrderDto dto) {
        log.info("提交订单参数:[{}]", dto);
        return orderService.submitOrder(dto);
    }

    /**
     * 获取订单详情
     */
    @GetMapping("/getOrderDetail")
    public Res<OrderConfirmsVo> getOrderDetail() {
        return orderService.getOrderDetail();
    }

    /**
     * 根据订单号获取订单状态
     *
     * @param orderSn 订单号
     * @return 订单
     */
    @GetMapping("/orderStatus")
    public Res<OmsOrderVo> getOrderStatusBySn(
            @RequestParam("orderSn")
            @NotNull(message = ORDER_SN_CANNOT_BE_NULL)
            String orderSn
    ) {
        log.info("根据订单号获取订单状态参数:[{}]", orderSn);
        return orderService.getOrderStatusBySn(orderSn);
    }
}
